<?php
class encode_trans{

	public function __construct(){
		
	}
	public function trans($dir){
		$file="";

		$dh=opendir($dir);
		while ($file=readdir($dh)){	
			if($file=="."||$file==".."){		 
				continue;
			}
			if(substr($file,-4)==".php"){
			    $filename=$dir."/".$file;
				$this->encode($filename);
				print $filename."<br />";
				
			}else{
				$subdir=$dir."/".$file;
				if(is_dir($subdir)){
					$this->trans($subdir);
				}else{
					
				}
			}
			 
		}
		
		
	}
	private  function encode($filename){
		//$opts = array('file' => array('encoding' => 'gbk')); 
		//$ctxt = stream_context_create($opts); 
		$content=file_get_contents($filename); 
		$content= iconv("gbk","utf-8",$content);
		$fp=fopen($filename,'w');
		//$content=utf8_encode($content);
		//$content = "\xEF\xBB\xBF".$content;   
	//	print $content; 
		 
		fputs($fp,$content);
		fclose($fp);
	}
	private function putInfo($flag,$str){
		if($flag){
			print "ok";
		}else{
			print "转换错误".$str;
		}
	}
}


$f= new encode_trans();
$f->trans("D:/servers/www/bcty365");



?>





